Write a C/C++ program to implement modular exponentiation using the algorithm described on page 23 of lecture 9 notes for public key cryptography (http://www.cse.usf.edu/~yliu/Network%20Security/lecture9.pdf). The requirements concerning your codes are 1) that it be written on your own with no assistance from persons other than the professor or the TA, and 2) that it be clear how the code works when read, which can be accomplished through any combination of variable and function names, comments, and code structure that you wish. Your codes must pass the following test cases (a^b mod n = result):
a |
b |
n |
result |
00000001 |
12345678 |
12345678 |
1 |
00000000 |
76543210 |
12345678 |
0 |
00000003 |
000fefef | 00000008 |
3 |
00000005 |
32348232 |
00000011 |
8 |
34433445 |
6cff454f |
00000011 |
9 |
7fffffff |
7eeeeeee |
7ddddddd |
74e6476c |
77777777 |
34839432 |
23498834 |
1d61f4c9 |
0facade0 |
0decade0 |
0abbabad |
3e29b63 |
Turn in:
Your source code files. Programs will be graded primarily on correctness of output, but no credit will be given for programs which do not use the basic algorithm covered in the lecture notes.
Hint: the product of two ints will often be too large to fit in an int and will overflow, but the product of two ints will always fit in a long.